package Pattern.SinglePattern.SingleTest;

public class DemoMultiThread {
    public static void main(String[] args) {
        System.out.println("如果看见相同的值，那么singleton被重用了"
                + "\n" + "如果看见不同的值，那么就创建了两个singletons"
                + "\n\n" + "result:" + "\n");

        Thread threadFoo = new Thread(new ThreadFoo());
        Thread threadBar = new Thread(new ThreadBar());

        threadFoo.start();
        threadBar.start();
    }
    static class ThreadFoo implements Runnable{
        @Override
        public void run() {
            Singleton2 singleton2 = Singleton2.getInstance("Foo");
            System.out.println(singleton2.value);
        }
    }

    static class ThreadBar implements Runnable{
        @Override
        public void run() {
            Singleton2 singleton2 = Singleton2.getInstance("Bar");
            System.out.println(singleton2.value);
        }
    }
}
